package services.fkgl;

import java.util.HashMap;
import java.util.List;
import com.PublicSystem;
/**
 * 单位发卡管理
 * @author duy
 *
 */
public class DwdjServices {
	PublicSystem sys = PublicSystem.getInstance();	
	/**
	 * 校验单位发卡数据
	 * @author duy
	 * @param obj
	 * @param parms
	 * @throws Exception
	 */
	public HashMap checkDWfk(HashMap obj) throws Exception {	 
		HashMap map = new HashMap();
		String ss = sys.callDBFuncProce("ic_az20.chk_dwfk", "function", obj).toString();		
		String[] msg = ss.split("&");
		if(!msg[0].equals("0")) {		
			map.put("msg", msg[0]);
			return  map;
		}				
		String str1 = sys.SelResultStr("select chr(1) from dual");
	    String str2 = sys.SelResultStr("select chr(2) from dual");
	    String str = ss.replaceAll("&", str1);
		String sss[] = str.split(str1);
		for (int i = 1; i < sss.length; i++) {								
		    String aa[] = sss[i].split(str2);	
		    if(aa.length == 1) {
			    map.put(aa[0], null);
			} else {
				map.put(aa[0], aa[1]);	
			}												
		}	
		return  map;
	} 		
	/**
	 * 查询单位发卡数据
	 * @author duy
	 * @param obj
	 * @param parms
	 * @throws Exception
	 */
	public HashMap getDWfk(Object[] obj, HashMap parms) throws Exception {
		String sql = "select * from zj_tmp where "
				+ "('"
				+ obj[0]
				+ "' is null or eventid = ?)";
		HashMap map = sys.getGrid(sql, obj, parms, false);
		return map;
	}	
	/**
	 * 根据id获取单位信息,判断是否存在符合条件的数据
	 * @author duy
	 * @param id
	 * @throws Exception
	 */
	public HashMap getDWfk1(String id) throws Exception {			
	    String sql = "select * from zj_tmp where eventid like '%'||?||'%'";
	    List data = sys.query(sql, new Object[] {id} , true);
	    return data.size() > 0 ? (HashMap)data.get(0) : null;	
	} 	
	/**
	 * 查询发卡详细信息
	 * @author duy
	 * @param obj
	 * @param parms
	 * @throws Exception
	 */	
	public HashMap getDWfkmx(Object[] obj, HashMap parms) throws Exception {
	    String  sql = "select aaz001,aae011,aac003,aac004,aaz501,aaz632 from az20 where " +
	    		"('"+ obj[0] +"' is null or aab001 = ?) and " +
	    		"('"+ obj[1] +"' is null or aaz001 = ?) and " +
	    		"('"+ obj[2] +"' is null or aaz002 = ?)";	    	
	    HashMap map = sys.getGrid(sql, obj, parms, true);
	    return map;
	} 			
	/**
	 * 新增单位发卡人员信息，利用存储过程获取
	 * @author duy
	 * @param obj
	 * @throws Exception
	 */
	public String saveDWfk(HashMap obj ) throws Exception {   
		String ss = sys.callDBFuncProce("ic_az20.set_fkdj_dw","function", obj);
		String[] str = ss.split("&");		
		if("0".equals(str[0])||null == str[0]) {
        	return "保存成功!";
        }
		else {		
        	return "保存失败:原因为" + str[0];
        }
	} 
	
}
